﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using SharepointSolutionInstaller.Resources;

namespace SharepointSolutionInstaller.Utils.RequiredChecks
{
    /// <summary>
    /// Checks if the current user is an administrator.
    /// </summary>
    internal class AdminRightsCheck : SystemCheck
    {
        internal AdminRightsCheck() : base("AdminRightsCheck") { }

        protected override SystemCheckResult DoExecute()
        {
            try
            {
                if (SPFarm.Local.CurrentUserIsAdministrator())
                {
                    return SystemCheckResult.Success;
                }
                return SystemCheckResult.Error;
            }

            catch (NullReferenceException)
            {
                throw new Exception(CommonUIStrings.installExceptionDatabase);
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        protected override bool CanRun
        {
            get { return IsWSSInstalled; }
        }
    }
}
